package com.rabbit.eap.framework.utils;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * @projectName eap
 * @packageName com.rabbit.eap.framework.utils
 * @className PasswordUtil
 * @author： rabbit
 * @version： 1.0
 * @since： 2020/5/31 00:35
 * <p>Description: PasswordUtil
 * 密码加密工具类
 * </p>

 */
public class PasswordUtil {
   /**
    * @Description 密码加盐，再加密
    * @methodName: encrypt
    * @param pwd: 密码
    * @param salt: 盐值
    * @return: java.lang.String
    * @date: 2020/5/31 00:36
    * @author: rabbit
    *
    */
    public static String encrypt(String pwd, String salt) {
        if (StringUtils.isBlank(pwd)) {
            throw new IllegalArgumentException("密码不能为空");
        }
        if (StringUtils.isBlank(salt)) {
            throw new IllegalArgumentException("盐值不能为空");
        }
        return DigestUtils.sha256Hex(pwd + salt);
    }

    public static void main(String[] args) {
       String pwd  =  PasswordUtil.encrypt("123456","123456");
        System.out.println(pwd);
    }

}
